﻿// =================================================================== 
// 项目说明
//====================================================================
// SunCity@Copy Right 2006-2008
// 文件： feedback.cs
// 项目名称：SunCity_MS
// 创建时间：2015/3/18
// 负责人：Chris
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using EMS20.Entity;
using EMS20.IDataAccessLayer;

namespace EMS20.DataAccessLayer
{
    /// <summary>
    /// 数据层实例化接口类 dbo.feedback.
    /// </summary>
    public partial class feedbackDataAccessLayer : IfeedbackDataAccessLayer
    {
		#region 构造函数
		/// <summary>
		/// ??????
		/// </summary>
		public feedbackDataAccessLayer()
		{
		}
		#endregion

        #region -----------实例化接口函数-----------
		
		#region 添加更新删除
		/// <summary>
		/// 向数据库中插入一条新记录。
		/// </summary>
		/// <param name="_feedbackModel">feedback实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Create_feedbackInsert(feedbackEntity _feedbackModel)
		{
			string sqlStr="CreateUpdateDelete_feedbackEntity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@DataAction",SqlDbType.Int),
			new SqlParameter("@f_id",SqlDbType.Int),
			new SqlParameter("@f_title",SqlDbType.VarChar),
			new SqlParameter("@f_content",SqlDbType.VarChar),
			new SqlParameter("@fuser_name",SqlDbType.VarChar),
			new SqlParameter("@fuser_tel",SqlDbType.VarChar),
			new SqlParameter("@fuser_qq",SqlDbType.VarChar),
			new SqlParameter("@fuser_email",SqlDbType.VarChar),
			new SqlParameter("@fadd_time",SqlDbType.DateTime),
			new SqlParameter("@freply_content",SqlDbType.VarChar),
			new SqlParameter("@freply_time",SqlDbType.DateTime),
			new SqlParameter("@is_lock",SqlDbType.Bit)
			};
			_param[0].Value=0;
			_param[1].Value=_feedbackModel.f_id;
			_param[2].Value=_feedbackModel.f_title;
			_param[3].Value=_feedbackModel.f_content;
			_param[4].Value=_feedbackModel.fuser_name;
			_param[5].Value=_feedbackModel.fuser_tel;
			_param[6].Value=_feedbackModel.fuser_qq;
			_param[7].Value=_feedbackModel.fuser_email;
			_param[8].Value=_feedbackModel.fadd_time;
			_param[9].Value=_feedbackModel.freply_content;
			_param[10].Value=_feedbackModel.freply_time;
			_param[11].Value=_feedbackModel.is_lock;
			res = (int)SqlHelper.ExecuteScalar(Conn.SqlConn,CommandType.StoredProcedure,sqlStr,_param);
			return res;
		}
		/// <summary>
		/// 向数据库中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_feedbackModel">feedback实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Create_feedbackInsert(SqlTransaction sp,feedbackEntity _feedbackModel)
		{
			string sqlStr="CreateUpdateDelete_feedbackEntity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@DataAction",SqlDbType.Int),
			new SqlParameter("@f_id",SqlDbType.Int),
			new SqlParameter("@f_title",SqlDbType.VarChar),
			new SqlParameter("@f_content",SqlDbType.VarChar),
			new SqlParameter("@fuser_name",SqlDbType.VarChar),
			new SqlParameter("@fuser_tel",SqlDbType.VarChar),
			new SqlParameter("@fuser_qq",SqlDbType.VarChar),
			new SqlParameter("@fuser_email",SqlDbType.VarChar),
			new SqlParameter("@fadd_time",SqlDbType.DateTime),
			new SqlParameter("@freply_content",SqlDbType.VarChar),
			new SqlParameter("@freply_time",SqlDbType.DateTime),
			new SqlParameter("@is_lock",SqlDbType.Bit)
			};
			_param[0].Value=0;
			_param[1].Value=_feedbackModel.f_id;
			_param[2].Value=_feedbackModel.f_title;
			_param[3].Value=_feedbackModel.f_content;
			_param[4].Value=_feedbackModel.fuser_name;
			_param[5].Value=_feedbackModel.fuser_tel;
			_param[6].Value=_feedbackModel.fuser_qq;
			_param[7].Value=_feedbackModel.fuser_email;
			_param[8].Value=_feedbackModel.fadd_time;
			_param[9].Value=_feedbackModel.freply_content;
			_param[10].Value=_feedbackModel.freply_time;
			_param[11].Value=_feedbackModel.is_lock;
			res = (int)SqlHelper.ExecuteScalar(sp,CommandType.StoredProcedure,sqlStr,_param);
			return res;
		}


		/// <summary>
		/// 向数据表feedback更新一条记录。
		/// </summary>
		/// <param name="_feedbackModel">_feedbackModel</param>
		/// <returns>影响的行数</returns>
		public int Create_feedbackUpdate(feedbackEntity _feedbackModel)
		{
            string sqlStr="CreateUpdateDelete_feedbackEntity";
			SqlParameter[] _param={
				new SqlParameter("@DataAction",SqlDbType.Int),
				new SqlParameter("@f_id",SqlDbType.Int),
				new SqlParameter("@f_title",SqlDbType.VarChar),
				new SqlParameter("@f_content",SqlDbType.VarChar),
				new SqlParameter("@fuser_name",SqlDbType.VarChar),
				new SqlParameter("@fuser_tel",SqlDbType.VarChar),
				new SqlParameter("@fuser_qq",SqlDbType.VarChar),
				new SqlParameter("@fuser_email",SqlDbType.VarChar),
				new SqlParameter("@fadd_time",SqlDbType.DateTime),
				new SqlParameter("@freply_content",SqlDbType.VarChar),
				new SqlParameter("@freply_time",SqlDbType.DateTime),
				new SqlParameter("@is_lock",SqlDbType.Bit)
				};
				_param[0].Value=1;
				_param[1].Value=_feedbackModel.f_id;
				_param[2].Value=_feedbackModel.f_title;
				_param[3].Value=_feedbackModel.f_content;
				_param[4].Value=_feedbackModel.fuser_name;
				_param[5].Value=_feedbackModel.fuser_tel;
				_param[6].Value=_feedbackModel.fuser_qq;
				_param[7].Value=_feedbackModel.fuser_email;
				_param[8].Value=_feedbackModel.fadd_time;
				_param[9].Value=_feedbackModel.freply_content;
				_param[10].Value=_feedbackModel.freply_time;
				_param[11].Value=_feedbackModel.is_lock;
			return SqlHelper.ExecuteNonQuery(Conn.SqlConn,CommandType.StoredProcedure,sqlStr,_param);
		}
		/// <summary>
		/// 向数据表feedback更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_feedbackModel">_feedbackModel</param>
		/// <returns>影响的行数</returns>
		public int Create_feedbackUpdate(SqlTransaction sp,feedbackEntity _feedbackModel)
		{
            string sqlStr="CreateUpdateDelete_feedbackEntity";
			SqlParameter[] _param={
				new SqlParameter("@DataAction",SqlDbType.Int),
				new SqlParameter("@f_id",SqlDbType.Int),
				new SqlParameter("@f_title",SqlDbType.VarChar),
				new SqlParameter("@f_content",SqlDbType.VarChar),
				new SqlParameter("@fuser_name",SqlDbType.VarChar),
				new SqlParameter("@fuser_tel",SqlDbType.VarChar),
				new SqlParameter("@fuser_qq",SqlDbType.VarChar),
				new SqlParameter("@fuser_email",SqlDbType.VarChar),
				new SqlParameter("@fadd_time",SqlDbType.DateTime),
				new SqlParameter("@freply_content",SqlDbType.VarChar),
				new SqlParameter("@freply_time",SqlDbType.DateTime),
				new SqlParameter("@is_lock",SqlDbType.Bit)
				};
				_param[0].Value=1;
				_param[1].Value=_feedbackModel.f_id;
				_param[2].Value=_feedbackModel.f_title;
				_param[3].Value=_feedbackModel.f_content;
				_param[4].Value=_feedbackModel.fuser_name;
				_param[5].Value=_feedbackModel.fuser_tel;
				_param[6].Value=_feedbackModel.fuser_qq;
				_param[7].Value=_feedbackModel.fuser_email;
				_param[8].Value=_feedbackModel.fadd_time;
				_param[9].Value=_feedbackModel.freply_content;
				_param[10].Value=_feedbackModel.freply_time;
				_param[11].Value=_feedbackModel.is_lock;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.StoredProcedure,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表feedback中的一条记录
		/// </summary>
	    /// <param name="f_id">f_id</param>
		/// <returns>影响的行数</returns>
		public int Create_feedbackDelete(int f_id)
		{
        feedbackEntity _feedbackModel =new feedbackEntity();
			string sqlStr="CreateUpdateDelete_feedbackEntity";
			SqlParameter[] _param={
			new SqlParameter("@DataAction",SqlDbType.VarChar),
			new SqlParameter("@f_id",SqlDbType.Int),			
			new SqlParameter("@f_title",SqlDbType.VarChar),
			new SqlParameter("@f_content",SqlDbType.VarChar),
			new SqlParameter("@fuser_name",SqlDbType.VarChar),
			new SqlParameter("@fuser_tel",SqlDbType.VarChar),
			new SqlParameter("@fuser_qq",SqlDbType.VarChar),
			new SqlParameter("@fuser_email",SqlDbType.VarChar),
			new SqlParameter("@fadd_time",SqlDbType.DateTime),
			new SqlParameter("@freply_content",SqlDbType.VarChar),
			new SqlParameter("@freply_time",SqlDbType.DateTime),
			new SqlParameter("@is_lock",SqlDbType.Bit)
			};
			_param[0].Value=2;
			_param[1].Value=f_id;
			_param[2].Value=_feedbackModel.f_title;
			_param[3].Value=_feedbackModel.f_content;
			_param[4].Value=_feedbackModel.fuser_name;
			_param[5].Value=_feedbackModel.fuser_tel;
			_param[6].Value=_feedbackModel.fuser_qq;
			_param[7].Value=_feedbackModel.fuser_email;
			_param[8].Value=_feedbackModel.fadd_time;
			_param[9].Value=_feedbackModel.freply_content;
			_param[10].Value=_feedbackModel.freply_time;
			_param[11].Value=_feedbackModel.is_lock;
			return SqlHelper.ExecuteNonQuery(Conn.SqlConn,CommandType.StoredProcedure,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表feedback中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="f_id">f_id</param>
		/// <returns>影响的行数</returns>
		public int Create_feedbackDelete(SqlTransaction sp,int f_id)
		{
         feedbackEntity _feedbackModel =new feedbackEntity();
			string sqlStr="CreateUpdateDelete_feedbackEntity";
			SqlParameter[] _param={
			new SqlParameter("@DataAction",SqlDbType.Int),
			new SqlParameter("@f_id",SqlDbType.Int),
			new SqlParameter("@f_title",SqlDbType.VarChar),
			new SqlParameter("@f_content",SqlDbType.VarChar),
			new SqlParameter("@fuser_name",SqlDbType.VarChar),
			new SqlParameter("@fuser_tel",SqlDbType.VarChar),
			new SqlParameter("@fuser_qq",SqlDbType.VarChar),
			new SqlParameter("@fuser_email",SqlDbType.VarChar),
			new SqlParameter("@fadd_time",SqlDbType.DateTime),
			new SqlParameter("@freply_content",SqlDbType.VarChar),
			new SqlParameter("@freply_time",SqlDbType.DateTime),
			new SqlParameter("@is_lock",SqlDbType.Bit)
			};
			_param[0].Value=2;
			_param[1].Value=f_id;
			_param[2].Value=_feedbackModel.f_title;
			_param[3].Value=_feedbackModel.f_content;
			_param[4].Value=_feedbackModel.fuser_name;
			_param[5].Value=_feedbackModel.fuser_tel;
			_param[6].Value=_feedbackModel.fuser_qq;
			_param[7].Value=_feedbackModel.fuser_email;
			_param[8].Value=_feedbackModel.fadd_time;
			_param[9].Value=_feedbackModel.freply_content;
			_param[10].Value=_feedbackModel.freply_time;
			_param[11].Value=_feedbackModel.is_lock;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.StoredProcedure,sqlStr,_param);
		}
		#endregion
		
		#region 数据实体
		/// <summary>
		/// 得到  feedback 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>feedback 数据实体</returns>
		public feedbackEntity Populate_feedbackEntity_FromDr(DataRow row)
		{
			feedbackEntity Obj = new feedbackEntity();
			if(row!=null)
			{
				Obj.f_id = (( row["f_id"])==DBNull.Value)?0:Convert.ToInt32( row["f_id"]);
				Obj.f_title =  row["f_title"].ToString();
				Obj.f_content =  row["f_content"].ToString();
				Obj.fuser_name =  row["fuser_name"].ToString();
				Obj.fuser_tel =  row["fuser_tel"].ToString();
				Obj.fuser_qq =  row["fuser_qq"].ToString();
				Obj.fuser_email =  row["fuser_email"].ToString();
				Obj.fadd_time = (( row["fadd_time"])==DBNull.Value)?Convert.ToDateTime(1900-1-1):Convert.ToDateTime( row["fadd_time"]);
				Obj.freply_content =  row["freply_content"].ToString();
				Obj.freply_time = (( row["freply_time"])==DBNull.Value)?Convert.ToDateTime(1900-1-1):Convert.ToDateTime( row["freply_time"]);
				Obj.is_lock = (bool) row["is_lock"];
			}
			else
			{
				return null;
			}
			return Obj;
		}
		
        /// <summary>
		/// 得到  feedback 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>feedback 数据实体</returns>
		public feedbackEntity Populate_feedbackEntity_FromDr(IDataReader dr)
		{
			feedbackEntity Obj = new feedbackEntity();
			
				Obj.f_id = (( dr["f_id"])==DBNull.Value)?0:Convert.ToInt32( dr["f_id"]);
				Obj.f_title =  dr["f_title"].ToString();
				Obj.f_content =  dr["f_content"].ToString();
				Obj.fuser_name =  dr["fuser_name"].ToString();
				Obj.fuser_tel =  dr["fuser_tel"].ToString();
				Obj.fuser_qq =  dr["fuser_qq"].ToString();
				Obj.fuser_email =  dr["fuser_email"].ToString();
				Obj.fadd_time = (( dr["fadd_time"])==DBNull.Value)?Convert.ToDateTime(1900-1-1):Convert.ToDateTime( dr["fadd_time"]);
				Obj.freply_content =  dr["freply_content"].ToString();
				Obj.freply_time = (( dr["freply_time"])==DBNull.Value)?Convert.ToDateTime(1900-1-1):Convert.ToDateTime( dr["freply_time"]);
				Obj.is_lock = (bool) dr["is_lock"];
			
			return Obj;
		}
		#endregion
		
		/// <summary>
		/// 根据ID,返回一个feedback对象
		/// </summary>
		/// <param name="f_id">f_id</param>
		/// <returns>feedback对象</returns>
		public feedbackEntity Get_feedbackEntity (int f_id)
		{
			feedbackEntity _obj=null;
			SqlParameter[] _param={
			new SqlParameter("@f_id",SqlDbType.Int)
			};
			_param[0].Value=f_id;
			string sqlStr="select * from feedback where f_id=@f_id";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(Conn.SqlConn,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=Populate_feedbackEntity_FromDr(dr);
				}
			}
			return _obj;
		}
		/// <summary>
		/// 得到数据表feedback所有记录
		/// </summary>
		/// <returns>数据集</returns>
		public IList< feedbackEntity> Get_feedbackAll()
		{
			IList< feedbackEntity> Obj=new List< feedbackEntity>();
			string sqlStr="select * from feedback";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(Conn.SqlConn,CommandType.Text,sqlStr))
			{
				while(dr.Read())
				{
					Obj.Add(Populate_feedbackEntity_FromDr(dr));
				}
			}
			return Obj;
		}
		/// <summary>
        /// 检测是否存在根据主键
        /// </summary>
        /// <param name="f_id">f_id</param>
        /// <returns>是/否</returns>
		public bool IsExistfeedback(int f_id)
		{
			SqlParameter[] _param={
                                      new SqlParameter("@f_id",SqlDbType.Int)
                                  };
            _param[0].Value=f_id;
            string sqlStr="select Count(*) from feedback where f_id=@f_id";
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConn,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

        #endregion
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
